// import { keys } from "lodash";
import * as ts from "./node_modules/typescript/lib/typescript";

function compile(fileNames: string[], options: ts.CompilerOptions): void {
  // Create a Program with an in-memory emit
  const createdFiles: { [key: string]: any } = {}
  const host = ts.createCompilerHost(options);
  host.writeFile = (fileName: string, contents: string) => createdFiles[fileName] = contents

  // Prepare and emit the d.ts files
  const program = ts.createProgram(fileNames, options, host);
  program.emit();

  // Loop through all the input files
  fileNames.forEach(file => {
    console.log("### JavaScript\n")
    console.log(host.readFile(file))

    console.log("### Type Definition\n")
    const dts = file.replace(".js", ".d.ts")
    console.log(createdFiles[dts])
  });

  console.log(createdFiles['./out/compiler-file.d.ts'])
  console.log(createdFiles['./out/compiler-file.js'])
  // console.log("## fileNames ", keys(createdFiles))
}

const files: string[] = ['D:\\SourceCode\\tmp\\TS-Compiler-Api\\compiler-file.ts'];
const options: ts.CompilerOptions = {
  baseUrl: ".",
  outDir: "./out",
  allowJs: true,
  target: ts.ScriptTarget.ES3,
  module: ts.ModuleKind.CommonJS,
  moduleResolution: ts.ModuleResolutionKind.Classic,
  sourceMap: true,
  inlineSourceMap: false,
  inlineSources: true,
  allowSyntheticDefaultImports: true,
  forceConsistentCasingInFileNames: true,
  noImplicitReturns: true,
  noUnusedLocals: true,
  experimentalDecorators: true,
  strict: true,
  checkJs: true,
  declaration: true,
  // declarationDir: "./build/declaration",
  skipLibCheck: true
};

compile(files, options);
